package org.belkodevelop.controller.interceptor;


import org.belkodevelop.announcement.service.AnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class PremiumAnnouncementInterceptor extends HandlerInterceptorAdapter {

    @Autowired
    private AnnouncementService announcementService;

    @Override
    public void postHandle(HttpServletRequest request,
                           HttpServletResponse response, Object handler,
                           ModelAndView modelAndView) throws Exception {

        if (modelAndView != null) {
            modelAndView.addObject("premiumAnnouncements", announcementService.getPremiumAnnouncements());
        }
        super.postHandle(request, response, handler, modelAndView);
    }
}
